use std::fmt;
use std::fmt::{Display, Formatter};
//OutlinePrint有个父trait Display。实现OutlinePrint 必须也得实现其父trait。
trait OutlinePrint: Display{
    fn outline_print(&self) {
        let output = self.to_string();
        let len = output.len();
        println!("{}", "*".repeat(len + 4));
        println!("*{}*", " ".repeat(len + 2));
        println!("* {} *", output);
        println!("*{}*", " ".repeat(len + 2));
        println!("{}", "*".repeat(len + 4));
    }
}
struct Point {
    x: i32,
    y: i32,
}

impl Display for Point {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}

impl OutlinePrint for Point {
}
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_outline_print() {
        let p = Point { x: 1, y: 2 };
        p.outline_print();
    }
}